package edu.office.applicationRepository;

import edu.office.entities.News;
import edu.office.tools.EOMessage;
import edu.office.tools.EOMessage1;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;

import java.util.List;


@Named("newsRepositoryA")
@ApplicationScoped
public class NewsRepository extends ApplicationCommonRepository<News> {

    public List<News> getNews4Roleinfo(Integer roleinfoId) {
        return find("FOR_ROLE", roleinfoId).list();
    }

    public List<News> getNews4Teacher(Integer teacherId) {
        return find("TEACHERNO", teacherId).list();
    }

    public List<News> getNewsByTitle(String title) {
        return find("NEWSTITLE", title).list();
    }

    public String myCreate(News news) {
        if (list("newstitle", news.getNEWSTITLE()).isEmpty()) {
            create(news);
            return EOMessage.getEOMessageENUM(EOMessage1.Succeed);
        } else {
            return EOMessage.getEOMessageENUM(EOMessage1.Already_Exist);
        }
    }
}
